from django.db import models
from home.models import JobCategories


# Create your models here.

# 角色表
# 资源表
# 角色资源表
# 用户基本表
# HR信息表
# 求职者信息表
# 第三方登录记录表
class Role(models.Model):
    # 角色名称：hr、普通求职、vip求职者
    name = models.CharField(max_length=100, verbose_name='角色名称')

    def __str__(self):
        return self.name

    class Meta:
        db_table = "role"


# 资源表
class Resource(models.Model):
    name = models.CharField(max_length=100, verbose_name='资源名称')
    url = models.CharField(max_length=500, verbose_name='资源路径')
    parent = models.ForeignKey('self', null=True, blank=True, verbose_name='父级资源id', on_delete=models.CASCADE,
                               related_name='children')

    def __str__(self):
        return self.name

    class Meta:
        db_table = "resource"


# 角色资源中间表
class Role_Resource(models.Model):
    role = models.ForeignKey(Role, verbose_name='角色id', on_delete=models.CASCADE)
    resource = models.ForeignKey(Resource, verbose_name='角色id', on_delete=models.CASCADE)

    class Meta:
        db_table = "role_resource"


# 用户基本信息表
class User(models.Model):
    phone = models.CharField(max_length=20, verbose_name='手机号', unique=True)
    role = models.ForeignKey(Role, verbose_name='角色id', on_delete=models.CASCADE)

    class Meta:
        db_table = "user"


# 城市表
class City(models.Model):
    name = models.CharField(max_length=100, verbose_name='城市名称')
    pid = models.ForeignKey('self', null=True, blank=True, verbose_name='父级城市id', on_delete=models.CASCADE,
                            related_name='children')

    class Meta:
        db_table = 'city'


# 公司表
class Company(models.Model):
    name = models.CharField(max_length=100, verbose_name='公司名称')
    logo = models.CharField(max_length=500, verbose_name='公司logo')
    city = models.ForeignKey(
        City, verbose_name='城市id', on_delete=models.CASCADE,
        # related_name='company'
    )

    def __str__(self):
        return self.name

    class Meta:
        db_table = "company"


# # HR信息表
# class HRInfo(models.Model):
#     phone=models.CharField(max_length=20,verbose_name='手机号',unique=True)
#     desc=models.TextField(verbose_name='简介')
#     department=models.CharField(max_length=20,verbose_name='部门',default="人力资源部")
#     position=models.CharField(max_length=20,verbose_name='职位',default='经理')
#     work_number=models.CharField(max_length=20,verbose_name='工号')
#     role=models.ForeignKey(Role,verbose_name='角色id',on_delete=models.CASCADE)
#     company=models.ForeignKey(Company,verbose_name='公司id',on_delete=models.CASCADE)
#
#     def __str__(self):
#         return self.phone
#     class Meta:
#         db_table="hrinfo"


# 求职者信息表
class JobInfo(models.Model):
    name = models.CharField(max_length=20, verbose_name='用户名', unique=True)
    sex = models.IntegerField(verbose_name='性别', choices=((1, '女'), (2, '男')))
    birthdate = models.DateField(verbose_name='出生日期')
    desc = models.TextField(verbose_name='简介/自我介绍')
    education = models.IntegerField(verbose_name='学历', choices=(
        (1, '初中以下'), (2, '初中'), (3, '中专'), (4, '高中'), (5, '大专'), (6, '本科'), (7, '硕士'),
        (8, '博士及以上')))
    current_status = models.IntegerField(verbose_name='当前状态', choices=(
        (1, '在职看机会'), (2, '离职'), (3, '在校生等'), (4, '兼职')))  # 当前状态(1-在职看机会,2-离职,3-在校生等)
    resume_url = models.CharField(max_length=500, verbose_name='简历URL')
    aveter = models.CharField(max_length=500, verbose_name='头像', default='')
    user = models.ForeignKey(User, verbose_name='用户id', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        db_table = "jobinfo"


# 简历表
class Resume(models.Model):
    jobinfo = models.ForeignKey(JobInfo, verbose_name='求职者id', on_delete=models.CASCADE)
    first_work_time = models.DateField(verbose_name='首次参加工作时间')
    recent_job = models.CharField(max_length=500, verbose_name='您最近工作的职位是')
    # job_categories = models.ForeignKey(JobCategories, verbose_name='职位类别id', on_delete=models.CASCADE)
    job_categories = models.ManyToManyField(
        JobCategories,
        related_name="resume_job_categories"  # 唯一反向名称
    )
    company = models.ForeignKey(Company, verbose_name='公司id', on_delete=models.CASCADE)
    work_time_start = models.DateField(verbose_name='在职时间-开始时间')
    work_time_end = models.DateField(verbose_name='在职时间-结束时间')
    skill = models.TextField(verbose_name='技能')
    work_content = models.TextField(verbose_name='工作内容')
    education_type = models.IntegerField(choices=((0, "全日制"), (1, "非全日制")), verbose_name='学历')
    university = models.CharField(max_length=100, verbose_name='毕业大学')
    major = models.CharField(max_length=100, verbose_name='专业')
    start_time = models.DateField(verbose_name='入学时间')
    end_time = models.DateField(verbose_name='毕业时间')
    student_experience = models.TextField(verbose_name='在校经历')
    city = models.ForeignKey(City, verbose_name='工作城市', on_delete=models.CASCADE)
    # expect_job = models.ForeignKey(JobCategories, verbose_name='期望职位', on_delete=models.CASCADE)
    expect_job = models.ForeignKey(
        JobCategories,
        on_delete=models.CASCADE,
        related_name="resume_expect_job"  # 唯一反向名称
    )
    expect_salary_start = models.IntegerField(verbose_name='期望月薪(开始)')
    expect_salary_end = models.IntegerField(verbose_name='期望月薪(结束)')
    # expect_job_category = models.ForeignKey(JobCategories, verbose_name='期望职位类别', on_delete=models.CASCADE)
    expect_job_category = models.ForeignKey(
        JobCategories,
        on_delete=models.CASCADE,
        related_name="resume_expect_job_category"  # 唯一反向名称
    )
    advantage = models.TextField(verbose_name='个人优势')

    class Meta:
        db_table = 'resume'


# 第三方登录记录表
class ThirdLogin(models.Model):
    userid = models.ForeignKey(User, verbose_name='用户id', on_delete=models.CASCADE)
    oauth_id = models.CharField(max_length=100, verbose_name='第三方登录id', unique=True)
    style = models.CharField(max_length=20, verbose_name='第三方登录类型')
    token = models.CharField(max_length=500, verbose_name='第三方登录token')

    class Meta:
        db_table = "thirdLogin"
